# -*- coding: utf-8 -*-
import os
import pytest
import time
import allure
import requests
from common.setting import ConfigHandler
from utils.readFilesUtils.get_yaml_data_analysis import CaseData
from utils.cacheUtils.cacheControl import Cache
from utils.readFilesUtils.get_all_files_path import get_all_files
from utils.logUtils.logControl import WARNING, INFO, ERROR
from Enums.yamlData_enum import YAMLDate
from utils.otherUtils.allureDate.allure_tools import allure_step, allure_step_no

def work_login_init():
    """
    获取登录的cookie
    :return:
    """
    url = "https://api.58moto.com/user/center/login/mobile"
    params = {

        'mobile': "JNjFvS3QYVGzOf%2F9dUFaHA%3D%3D",
        'code': 1234,
        'riskControlDeviceId': "BPC5BlzQUyZuQ3cGG0Nksukz7uSTSi%2FyS9Djjk9tHZRClnba7QCMQjNANZUwXH%2FrJS%2BePTY8YWCBETOrAHjp%2BQw%3D%3D"
    }
    headers = {'Content-Type': 'application/x-www-form-urlencoded'}
    # 请求登录接口
    res = requests.post(url=url, params=params, verify=True, headers=headers)
    response_cookie = res.cookies

    cookies = ''
    print(cookies)
    for k, v in response_cookie.items():
        _cookie = k + "=" + v + ";"
        # 拿到登录的cookie内容，cookie拿到的是字典类型，转换成对应的格式
        cookies += _cookie
        # 将登录接口中的cookie写入缓存中，其中login_cookie是缓存名称
        Cache('login_cookie').set_caches(cookies)
        print(cookies)
